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

Side by Side Diff: pkg/kernel/lib/ast.dart

Issue 2952883003: Make the kernel API for promoted type parameter bounds less error-prone. (Closed)
Patch Set: Created 3 years, 5 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) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 /// ----------------------------------------------------------------------- 5 /// -----------------------------------------------------------------------
6 /// ERROR HANDLING 6 /// ERROR HANDLING
7 /// ----------------------------------------------------------------------- 7 /// -----------------------------------------------------------------------
8 /// 8 ///
9 /// As a rule of thumb, errors that can be detected statically are handled by 9 /// As a rule of thumb, errors that can be detected statically are handled by
10 /// the frontend, typically by translating the erroneous code into a 'throw' or 10 /// the frontend, typically by translating the erroneous code into a 'throw' or
(...skipping 4226 matching lines...) Expand 10 before | Expand all | Expand 10 after
4237 /// bound. A bound of `null` indicates that the bound has not been promoted and 4237 /// bound. A bound of `null` indicates that the bound has not been promoted and
4238 /// is the same as the [TypeParameter]'s bound. This allows one to detect 4238 /// is the same as the [TypeParameter]'s bound. This allows one to detect
4239 /// whether the bound has been promoted. 4239 /// whether the bound has been promoted.
4240 class TypeParameterType extends DartType { 4240 class TypeParameterType extends DartType {
4241 TypeParameter parameter; 4241 TypeParameter parameter;
4242 4242
4243 /// An optional promoted bound on the type parameter. 4243 /// An optional promoted bound on the type parameter.
4244 /// 4244 ///
4245 /// 'null' indicates that the type parameter's bound has not been promoted and 4245 /// 'null' indicates that the type parameter's bound has not been promoted and
4246 /// is therefore the same as the bound of [parameter]. 4246 /// is therefore the same as the bound of [parameter].
4247 DartType bound; 4247 DartType promotedBound;
4248 4248
4249 TypeParameterType(this.parameter, [this.bound]); 4249 TypeParameterType(this.parameter, [this.promotedBound]);
4250 4250
4251 accept(DartTypeVisitor v) => v.visitTypeParameterType(this); 4251 accept(DartTypeVisitor v) => v.visitTypeParameterType(this);
4252 4252
4253 visitChildren(Visitor v) {} 4253 visitChildren(Visitor v) {}
4254 4254
4255 bool operator ==(Object other) { 4255 bool operator ==(Object other) {
4256 return other is TypeParameterType && parameter == other.parameter; 4256 return other is TypeParameterType && parameter == other.parameter;
4257 } 4257 }
4258 4258
4259 int get hashCode => _temporaryHashCodeTable[parameter] ?? parameter.hashCode; 4259 int get hashCode => _temporaryHashCodeTable[parameter] ?? parameter.hashCode;
4260
4261 /// Returns the bound of the type parameter, accounting for promotions.
4262 DartType get bound => promotedBound ?? parameter.bound;
4260 } 4263 }
4261 4264
4262 /// Declaration of a type variable. 4265 /// Declaration of a type variable.
4263 /// 4266 ///
4264 /// Type parameters declared in a [Class] or [FunctionNode] are part of the AST, 4267 /// Type parameters declared in a [Class] or [FunctionNode] are part of the AST,
4265 /// have a parent pointer to its declaring class or function, and will be seen 4268 /// have a parent pointer to its declaring class or function, and will be seen
4266 /// by tree visitors. 4269 /// by tree visitors.
4267 /// 4270 ///
4268 /// Type parameters declared by a [FunctionType] are orphans and have a `null` 4271 /// Type parameters declared by a [FunctionType] are orphans and have a `null`
4269 /// parent pointer. [TypeParameter] objects should not be shared between 4272 /// parent pointer. [TypeParameter] objects should not be shared between
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
4616 /// typedef has not been assigned a canonical name yet. 4619 /// typedef has not been assigned a canonical name yet.
4617 /// 4620 ///
4618 /// Returns `null` if the typedef is `null`. 4621 /// Returns `null` if the typedef is `null`.
4619 CanonicalName getCanonicalNameOfTypedef(Typedef typedef_) { 4622 CanonicalName getCanonicalNameOfTypedef(Typedef typedef_) {
4620 if (typedef_ == null) return null; 4623 if (typedef_ == null) return null;
4621 if (typedef_.canonicalName == null) { 4624 if (typedef_.canonicalName == null) {
4622 throw '$typedef_ has no canonical name'; 4625 throw '$typedef_ has no canonical name';
4623 } 4626 }
4624 return typedef_.canonicalName; 4627 return typedef_.canonicalName;
4625 } 4628 }
OLDNEW
« no previous file with comments | « pkg/front_end/lib/src/fasta/kernel/kernel_shadow_ast.dart ('k') | pkg/kernel/lib/binary/ast_to_binary.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698