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

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

Issue 1674073002: Add UnlinkedConst.isValid and set it during summarizing. (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
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 analyzer.test.src.summary.summary_common; 5 library analyzer.test.src.summary.summary_common;
6 6
7 import 'package:analyzer/analyzer.dart'; 7 import 'package:analyzer/analyzer.dart';
8 import 'package:analyzer/dart/ast/ast.dart'; 8 import 'package:analyzer/dart/ast/ast.dart';
9 import 'package:analyzer/dart/element/element.dart'; 9 import 'package:analyzer/dart/element/element.dart';
10 import 'package:analyzer/src/generated/engine.dart'; 10 import 'package:analyzer/src/generated/engine.dart';
(...skipping 3870 matching lines...) Expand 10 before | Expand all | Expand 10 after
3881 } 3881 }
3882 3882
3883 test_field_final() { 3883 test_field_final() {
3884 UnlinkedVariable variable = 3884 UnlinkedVariable variable =
3885 serializeClassText('class C { final int i = 0; }').fields[0]; 3885 serializeClassText('class C { final int i = 0; }').fields[0];
3886 expect(variable.isFinal, isTrue); 3886 expect(variable.isFinal, isTrue);
3887 _assertUnlinkedConst(variable.constExpr, 3887 _assertUnlinkedConst(variable.constExpr,
3888 operators: [UnlinkedConstOperation.pushInt], ints: [0]); 3888 operators: [UnlinkedConstOperation.pushInt], ints: [0]);
3889 } 3889 }
3890 3890
3891 test_field_final_invalidConstExpr() {
3892 UnlinkedVariable variable = serializeClassText(r'''
3893 class C {
3894 final int f = 1 + m();
3895 static int m() => 42;
3896 }''').fields[0];
3897 expect(variable.isFinal, isTrue);
3898 _assertUnlinkedConst(variable.constExpr, isValid: false);
3899 }
3900
3891 test_field_formal_param_inferred_type_explicit() { 3901 test_field_formal_param_inferred_type_explicit() {
3892 UnlinkedClass cls = serializeClassText( 3902 UnlinkedClass cls = serializeClassText(
3893 'class C extends D { var v; C(int this.v); }' 3903 'class C extends D { var v; C(int this.v); }'
3894 ' abstract class D { num get v; }', 3904 ' abstract class D { num get v; }',
3895 className: 'C'); 3905 className: 'C');
3896 checkInferredTypeSlot( 3906 checkInferredTypeSlot(
3897 cls.fields[0].inferredTypeSlot, 'dart:core', 'dart:core', 'num'); 3907 cls.fields[0].inferredTypeSlot, 'dart:core', 'dart:core', 'num');
3898 expect(cls.executables[0].kind, UnlinkedExecutableKind.constructor); 3908 expect(cls.executables[0].kind, UnlinkedExecutableKind.constructor);
3899 expect(cls.executables[0].parameters[0].inferredTypeSlot, 0); 3909 expect(cls.executables[0].parameters[0].inferredTypeSlot, 0);
3900 } 3910 }
(...skipping 1517 matching lines...) Expand 10 before | Expand all | Expand 10 after
5418 // This reference should have a dependency of 0, since it refers to 5428 // This reference should have a dependency of 0, since it refers to
5419 // an element that is contained within some other element. 5429 // an element that is contained within some other element.
5420 expect(reference.dependency, 0, 5430 expect(reference.dependency, 0,
5421 reason: 'Nonzero dependency for ${reference.kind}'); 5431 reason: 'Nonzero dependency for ${reference.kind}');
5422 } 5432 }
5423 } 5433 }
5424 } 5434 }
5425 } 5435 }
5426 5436
5427 void _assertUnlinkedConst(UnlinkedConst constExpr, 5437 void _assertUnlinkedConst(UnlinkedConst constExpr,
5428 {List<UnlinkedConstOperation> operators, 5438 {bool isValid: true,
5439 List<UnlinkedConstOperation> operators: const <UnlinkedConstOperation>[],
5429 List<int> ints: const <int>[], 5440 List<int> ints: const <int>[],
5430 List<double> doubles: const <double>[], 5441 List<double> doubles: const <double>[],
5431 List<String> strings: const <String>[], 5442 List<String> strings: const <String>[],
5432 List<_EntityRefValidator> referenceValidators: 5443 List<_EntityRefValidator> referenceValidators:
5433 const <_EntityRefValidator>[]}) { 5444 const <_EntityRefValidator>[]}) {
5434 expect(constExpr, isNotNull); 5445 expect(constExpr, isNotNull);
5446 expect(constExpr.isValid, isValid);
5435 expect(constExpr.operations, operators); 5447 expect(constExpr.operations, operators);
5436 expect(constExpr.ints, ints); 5448 expect(constExpr.ints, ints);
5437 expect(constExpr.doubles, doubles); 5449 expect(constExpr.doubles, doubles);
5438 expect(constExpr.strings, strings); 5450 expect(constExpr.strings, strings);
5439 expect(constExpr.references, hasLength(referenceValidators.length)); 5451 expect(constExpr.references, hasLength(referenceValidators.length));
5440 for (int i = 0; i < referenceValidators.length; i++) { 5452 for (int i = 0; i < referenceValidators.length; i++) {
5441 referenceValidators[i](constExpr.references[i]); 5453 referenceValidators[i](constExpr.references[i]);
5442 } 5454 }
5443 } 5455 }
5444 } 5456 }
5445 5457
5446 /** 5458 /**
5447 * Description of expectations for a prelinked prefix reference. 5459 * Description of expectations for a prelinked prefix reference.
5448 */ 5460 */
5449 class _PrefixExpectation { 5461 class _PrefixExpectation {
5450 final ReferenceKind kind; 5462 final ReferenceKind kind;
5451 final String name; 5463 final String name;
5452 final bool inLibraryDefiningUnit; 5464 final bool inLibraryDefiningUnit;
5453 final String absoluteUri; 5465 final String absoluteUri;
5454 final String relativeUri; 5466 final String relativeUri;
5455 final int numTypeParameters; 5467 final int numTypeParameters;
5456 5468
5457 _PrefixExpectation(this.kind, this.name, 5469 _PrefixExpectation(this.kind, this.name,
5458 {this.inLibraryDefiningUnit: false, 5470 {this.inLibraryDefiningUnit: false,
5459 this.absoluteUri, 5471 this.absoluteUri,
5460 this.relativeUri, 5472 this.relativeUri,
5461 this.numTypeParameters: 0}); 5473 this.numTypeParameters: 0});
5462 } 5474 }
OLDNEW
« pkg/analyzer/lib/src/summary/idl.dart ('K') | « pkg/analyzer/lib/src/summary/summarize_elements.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698