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

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

Issue 2767773004: Add Vector type to Kernel (Closed)
Patch Set: Update binary.md file to include Vector AST nodes Created 3 years, 9 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 library kernel.type_algebra; 4 library kernel.type_algebra;
5 5
6 import 'ast.dart'; 6 import 'ast.dart';
7 7
8 /// Returns a type where all occurrences of the given type parameters have been 8 /// Returns a type where all occurrences of the given type parameters have been
9 /// replaced with the corresponding types. 9 /// replaced with the corresponding types.
10 /// 10 ///
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 if (useCounter == before) return node; 358 if (useCounter == before) return node;
359 return new NamedType(node.name, type); 359 return new NamedType(node.name, type);
360 } 360 }
361 361
362 DartType visit(DartType node) => node.accept(this); 362 DartType visit(DartType node) => node.accept(this);
363 363
364 DartType visitInvalidType(InvalidType node) => node; 364 DartType visitInvalidType(InvalidType node) => node;
365 DartType visitDynamicType(DynamicType node) => node; 365 DartType visitDynamicType(DynamicType node) => node;
366 DartType visitVoidType(VoidType node) => node; 366 DartType visitVoidType(VoidType node) => node;
367 DartType visitBottomType(BottomType node) => node; 367 DartType visitBottomType(BottomType node) => node;
368 DartType visitVector(VectorType node) => node;
368 369
369 DartType visitInterfaceType(InterfaceType node) { 370 DartType visitInterfaceType(InterfaceType node) {
370 if (node.typeArguments.isEmpty) return node; 371 if (node.typeArguments.isEmpty) return node;
371 int before = useCounter; 372 int before = useCounter;
372 var typeArguments = node.typeArguments.map(visit).toList(); 373 var typeArguments = node.typeArguments.map(visit).toList();
373 if (useCounter == before) return node; 374 if (useCounter == before) return node;
374 return new InterfaceType(node.classNode, typeArguments); 375 return new InterfaceType(node.classNode, typeArguments);
375 } 376 }
376 377
377 List<TypeParameter> freshTypeParameters(List<TypeParameter> parameters) { 378 List<TypeParameter> freshTypeParameters(List<TypeParameter> parameters) {
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 } 533 }
533 534
534 bool _unify(DartType type1, DartType type2) { 535 bool _unify(DartType type1, DartType type2) {
535 if (!success) return false; 536 if (!success) return false;
536 type1 = type1 is TypeParameterType ? _substituteHead(type1) : type1; 537 type1 = type1 is TypeParameterType ? _substituteHead(type1) : type1;
537 type2 = type2 is TypeParameterType ? _substituteHead(type2) : type2; 538 type2 = type2 is TypeParameterType ? _substituteHead(type2) : type2;
538 if (type1 is DynamicType && type2 is DynamicType) return true; 539 if (type1 is DynamicType && type2 is DynamicType) return true;
539 if (type1 is VoidType && type2 is VoidType) return true; 540 if (type1 is VoidType && type2 is VoidType) return true;
540 if (type1 is InvalidType && type2 is InvalidType) return true; 541 if (type1 is InvalidType && type2 is InvalidType) return true;
541 if (type1 is BottomType && type2 is BottomType) return true; 542 if (type1 is BottomType && type2 is BottomType) return true;
543 if (type1 is VectorType && type2 is VectorType) return true;
542 if (type1 is InterfaceType && type2 is InterfaceType) { 544 if (type1 is InterfaceType && type2 is InterfaceType) {
543 if (type1.classNode != type2.classNode) return _fail(); 545 if (type1.classNode != type2.classNode) return _fail();
544 assert(type1.typeArguments.length == type2.typeArguments.length); 546 assert(type1.typeArguments.length == type2.typeArguments.length);
545 for (int i = 0; i < type1.typeArguments.length; ++i) { 547 for (int i = 0; i < type1.typeArguments.length; ++i) {
546 if (!_unify(type1.typeArguments[i], type2.typeArguments[i])) { 548 if (!_unify(type1.typeArguments[i], type2.typeArguments[i])) {
547 return false; 549 return false;
548 } 550 }
549 } 551 }
550 return true; 552 return true;
551 } 553 }
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
640 642
641 bool visit(DartType node) => node.accept(this); 643 bool visit(DartType node) => node.accept(this);
642 644
643 bool visitNamedType(NamedType node) { 645 bool visitNamedType(NamedType node) {
644 return visit(node.type); 646 return visit(node.type);
645 } 647 }
646 648
647 bool visitInvalidType(InvalidType node) => false; 649 bool visitInvalidType(InvalidType node) => false;
648 bool visitDynamicType(DynamicType node) => false; 650 bool visitDynamicType(DynamicType node) => false;
649 bool visitVoidType(VoidType node) => false; 651 bool visitVoidType(VoidType node) => false;
652 bool visitVectorType(VectorType node) => false;
650 653
651 bool visitInterfaceType(InterfaceType node) { 654 bool visitInterfaceType(InterfaceType node) {
652 return node.typeArguments.any(visit); 655 return node.typeArguments.any(visit);
653 } 656 }
654 657
655 bool visitFunctionType(FunctionType node) { 658 bool visitFunctionType(FunctionType node) {
656 return node.typeParameters.any(handleTypeParameter) || 659 return node.typeParameters.any(handleTypeParameter) ||
657 node.positionalParameters.any(visit) || 660 node.positionalParameters.any(visit) ||
658 node.namedParameters.any(visitNamedType) || 661 node.namedParameters.any(visitNamedType) ||
659 visit(node.returnType); 662 visit(node.returnType);
660 } 663 }
661 664
662 bool visitTypeParameterType(TypeParameterType node) { 665 bool visitTypeParameterType(TypeParameterType node) {
663 return variables == null || variables.contains(node.parameter); 666 return variables == null || variables.contains(node.parameter);
664 } 667 }
665 668
666 bool handleTypeParameter(TypeParameter node) { 669 bool handleTypeParameter(TypeParameter node) {
667 assert(!variables.contains(node)); 670 assert(!variables.contains(node));
668 return node.bound.accept(this); 671 return node.bound.accept(this);
669 } 672 }
670 } 673 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698