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

Side by Side Diff: lib/ast.dart

Issue 2439043002: Introduce Substitution class and Supertype class. (Closed)
Patch Set: Created 4 years, 2 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 | « lib/analyzer/loader.dart ('k') | lib/binary/ast_from_binary.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) 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 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 /// applications. 286 /// applications.
287 String name; 287 String name;
288 bool isAbstract; 288 bool isAbstract;
289 289
290 /// The uri of the source file this class was loaded from. 290 /// The uri of the source file this class was loaded from.
291 String fileUri; 291 String fileUri;
292 292
293 final List<TypeParameter> typeParameters; 293 final List<TypeParameter> typeParameters;
294 294
295 /// The immediate super type, or `null` if this is the root class. 295 /// The immediate super type, or `null` if this is the root class.
296 InterfaceType supertype; 296 Supertype supertype;
297 297
298 /// The mixed-in type if this is a mixin application, otherwise `null`. 298 /// The mixed-in type if this is a mixin application, otherwise `null`.
299 InterfaceType mixedInType; 299 Supertype mixedInType;
300 300
301 /// The types from the `implements` clause. 301 /// The types from the `implements` clause.
302 final List<InterfaceType> implementedTypes; 302 final List<Supertype> implementedTypes;
303 303
304 /// Fields declared in the class. 304 /// Fields declared in the class.
305 /// 305 ///
306 /// For mixin applications this should be empty. 306 /// For mixin applications this should be empty.
307 final List<Field> fields; 307 final List<Field> fields;
308 308
309 /// Constructors declared in the class. 309 /// Constructors declared in the class.
310 final List<Constructor> constructors; 310 final List<Constructor> constructors;
311 311
312 /// Procedures declared in the class. 312 /// Procedures declared in the class.
313 /// 313 ///
314 /// For mixin applications this should be empty. 314 /// For mixin applications this should be empty.
315 final List<Procedure> procedures; 315 final List<Procedure> procedures;
316 316
317 Class( 317 Class(
318 {this.name, 318 {this.name,
319 this.isAbstract: false, 319 this.isAbstract: false,
320 this.supertype, 320 this.supertype,
321 this.mixedInType, 321 this.mixedInType,
322 List<TypeParameter> typeParameters, 322 List<TypeParameter> typeParameters,
323 List<InterfaceType> implementedTypes, 323 List<InterfaceType> implementedTypes,
324 List<Constructor> constructors, 324 List<Constructor> constructors,
325 List<Procedure> procedures, 325 List<Procedure> procedures,
326 List<Field> fields, 326 List<Field> fields,
327 this.fileUri}) 327 this.fileUri})
328 : this.typeParameters = typeParameters ?? <TypeParameter>[], 328 : this.typeParameters = typeParameters ?? <TypeParameter>[],
329 this.implementedTypes = implementedTypes ?? <InterfaceType>[], 329 this.implementedTypes = implementedTypes ?? <Supertype>[],
330 this.fields = fields ?? <Field>[], 330 this.fields = fields ?? <Field>[],
331 this.constructors = constructors ?? <Constructor>[], 331 this.constructors = constructors ?? <Constructor>[],
332 this.procedures = procedures ?? <Procedure>[] { 332 this.procedures = procedures ?? <Procedure>[] {
333 setParents(this.typeParameters, this); 333 setParents(this.typeParameters, this);
334 setParents(this.constructors, this); 334 setParents(this.constructors, this);
335 setParents(this.procedures, this); 335 setParents(this.procedures, this);
336 setParents(this.fields, this); 336 setParents(this.fields, this);
337 } 337 }
338 338
339 /// The immediate super class, or `null` if this is the root class. 339 /// The immediate super class, or `null` if this is the root class.
(...skipping 14 matching lines...) Expand all
354 /// 354 ///
355 /// This getter is for convenience, not efficiency. Consider manually 355 /// This getter is for convenience, not efficiency. Consider manually
356 /// iterating the members to speed up code in production. 356 /// iterating the members to speed up code in production.
357 Iterable<Member> get members => 357 Iterable<Member> get members =>
358 <Iterable<Member>>[fields, constructors, procedures].expand((x) => x); 358 <Iterable<Member>>[fields, constructors, procedures].expand((x) => x);
359 359
360 /// The immediately extended, mixed-in, and implemented types. 360 /// The immediately extended, mixed-in, and implemented types.
361 /// 361 ///
362 /// This getter is for convenience, not efficiency. Consider manually 362 /// This getter is for convenience, not efficiency. Consider manually
363 /// iterating the super types to speed up code in production. 363 /// iterating the super types to speed up code in production.
364 Iterable<InterfaceType> get supers => <Iterable<InterfaceType>>[ 364 Iterable<Supertype> get supers => <Iterable<Supertype>>[
365 supertype == null ? const [] : [supertype], 365 supertype == null ? const [] : [supertype],
366 mixedInType == null ? const [] : [mixedInType], 366 mixedInType == null ? const [] : [mixedInType],
367 implementedTypes 367 implementedTypes
368 ].expand((x) => x); 368 ].expand((x) => x);
369 369
370 /// The library containing this class. 370 /// The library containing this class.
371 Library get enclosingLibrary => parent; 371 Library get enclosingLibrary => parent;
372 372
373 /// Adds a member to this class. 373 /// Adds a member to this class.
374 /// 374 ///
(...skipping 23 matching lines...) Expand all
398 accept(TreeVisitor v) => v.visitClass(this); 398 accept(TreeVisitor v) => v.visitClass(this);
399 acceptReference(Visitor v) => v.visitClassReference(this); 399 acceptReference(Visitor v) => v.visitClassReference(this);
400 400
401 /// If true, the class is part of an external library, that is, it is defined 401 /// If true, the class is part of an external library, that is, it is defined
402 /// in another build unit. Only a subset of its members are present. 402 /// in another build unit. Only a subset of its members are present.
403 /// 403 ///
404 /// These classes should be loaded at either [ClassLevel.Type] or 404 /// These classes should be loaded at either [ClassLevel.Type] or
405 /// [ClassLevel.Hierarchy] level. 405 /// [ClassLevel.Hierarchy] level.
406 bool get isInExternalLibrary => enclosingLibrary.isExternal; 406 bool get isInExternalLibrary => enclosingLibrary.isExternal;
407 407
408 Supertype get asRawSupertype {
409 return new Supertype(this,
410 new List<DartType>.filled(typeParameters.length, const DynamicType()));
411 }
412
413 Supertype get asThisSupertype {
414 return new Supertype(this, _getAsTypeArguments(typeParameters));
415 }
416
408 InterfaceType _rawType; 417 InterfaceType _rawType;
409 InterfaceType get rawType => _rawType ??= new InterfaceType(this); 418 InterfaceType get rawType => _rawType ??= new InterfaceType(this);
410 419
411 InterfaceType _thisType; 420 InterfaceType _thisType;
412 InterfaceType get thisType { 421 InterfaceType get thisType {
413 return _thisType ??= 422 return _thisType ??=
414 new InterfaceType(this, _getAsTypeArguments(typeParameters)); 423 new InterfaceType(this, _getAsTypeArguments(typeParameters));
415 } 424 }
416 425
417 InterfaceType _bottomType; 426 InterfaceType _bottomType;
(...skipping 14 matching lines...) Expand all
432 visitList(implementedTypes, v); 441 visitList(implementedTypes, v);
433 visitList(constructors, v); 442 visitList(constructors, v);
434 visitList(procedures, v); 443 visitList(procedures, v);
435 visitList(fields, v); 444 visitList(fields, v);
436 } 445 }
437 446
438 transformChildren(Transformer v) { 447 transformChildren(Transformer v) {
439 transformList(annotations, v, this); 448 transformList(annotations, v, this);
440 transformList(typeParameters, v, this); 449 transformList(typeParameters, v, this);
441 if (supertype != null) { 450 if (supertype != null) {
442 supertype = v.visitDartType(supertype); 451 supertype = v.visitSupertype(supertype);
443 } 452 }
444 if (mixedInType != null) { 453 if (mixedInType != null) {
445 mixedInType = v.visitDartType(mixedInType); 454 mixedInType = v.visitSupertype(mixedInType);
446 } 455 }
447 transformTypeList(implementedTypes, v); 456 transformSupertypeList(implementedTypes, v);
448 transformList(constructors, v, this); 457 transformList(constructors, v, this);
449 transformList(procedures, v, this); 458 transformList(procedures, v, this);
450 transformList(fields, v, this); 459 transformList(fields, v, this);
451 } 460 }
452 } 461 }
453 462
454 // ------------------------------------------------------------------------ 463 // ------------------------------------------------------------------------
455 // MEMBERS 464 // MEMBERS
456 // ------------------------------------------------------------------------ 465 // ------------------------------------------------------------------------
457 466
(...skipping 846 matching lines...) Expand 10 before | Expand all | Expand 10 after
1304 1313
1305 void set interfaceTarget(Member newTarget) { 1314 void set interfaceTarget(Member newTarget) {
1306 _interfaceTargetReference = newTarget?._getterInterface; 1315 _interfaceTargetReference = newTarget?._getterInterface;
1307 } 1316 }
1308 1317
1309 DartType getStaticType(TypeEnvironment types) { 1318 DartType getStaticType(TypeEnvironment types) {
1310 var interfaceTarget = this.interfaceTarget; 1319 var interfaceTarget = this.interfaceTarget;
1311 if (interfaceTarget != null) { 1320 if (interfaceTarget != null) {
1312 Class superclass = interfaceTarget.enclosingClass; 1321 Class superclass = interfaceTarget.enclosingClass;
1313 var receiverType = receiver.getStaticTypeAsInstanceOf(superclass, types); 1322 var receiverType = receiver.getStaticTypeAsInstanceOf(superclass, types);
1314 return substituteThisType(interfaceTarget.getterType, receiverType); 1323 return Substitution
1324 .fromInterfaceType(receiverType)
1325 .substituteType(interfaceTarget.getterType);
1315 } 1326 }
1316 // Treat the properties of Object specially. 1327 // Treat the properties of Object specially.
1317 String nameString = name.name; 1328 String nameString = name.name;
1318 if (nameString == 'hashCode') { 1329 if (nameString == 'hashCode') {
1319 return types.intType; 1330 return types.intType;
1320 } else if (nameString == 'runtimeType') { 1331 } else if (nameString == 'runtimeType') {
1321 return types.typeType; 1332 return types.typeType;
1322 } 1333 }
1323 return const DynamicType(); 1334 return const DynamicType();
1324 } 1335 }
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
1401 receiver = receiver.accept(v); 1412 receiver = receiver.accept(v);
1402 receiver?.parent = this; 1413 receiver?.parent = this;
1403 } 1414 }
1404 } 1415 }
1405 1416
1406 accept(ExpressionVisitor v) => v.visitDirectPropertyGet(this); 1417 accept(ExpressionVisitor v) => v.visitDirectPropertyGet(this);
1407 1418
1408 DartType getStaticType(TypeEnvironment types) { 1419 DartType getStaticType(TypeEnvironment types) {
1409 Class superclass = target.enclosingClass; 1420 Class superclass = target.enclosingClass;
1410 var receiverType = receiver.getStaticTypeAsInstanceOf(superclass, types); 1421 var receiverType = receiver.getStaticTypeAsInstanceOf(superclass, types);
1411 return substituteThisType(target.getterType, receiverType); 1422 return Substitution
1423 .fromInterfaceType(receiverType)
1424 .substituteType(target.getterType);
1412 } 1425 }
1413 } 1426 }
1414 1427
1415 /// Directly assign a field, or call a setter. 1428 /// Directly assign a field, or call a setter.
1416 class DirectPropertySet extends Expression { 1429 class DirectPropertySet extends Expression {
1417 Expression receiver; 1430 Expression receiver;
1418 Member target; 1431 Member target;
1419 Expression value; 1432 Expression value;
1420 1433
1421 DirectPropertySet(this.receiver, this.target, this.value) { 1434 DirectPropertySet(this.receiver, this.target, this.value) {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1475 1488
1476 accept(ExpressionVisitor v) => v.visitDirectMethodInvocation(this); 1489 accept(ExpressionVisitor v) => v.visitDirectMethodInvocation(this);
1477 1490
1478 DartType getStaticType(TypeEnvironment types) { 1491 DartType getStaticType(TypeEnvironment types) {
1479 if (types.isOverloadedArithmeticOperator(target)) { 1492 if (types.isOverloadedArithmeticOperator(target)) {
1480 return types.getTypeOfOverloadedArithmetic(receiver.getStaticType(types), 1493 return types.getTypeOfOverloadedArithmetic(receiver.getStaticType(types),
1481 arguments.positional[0].getStaticType(types)); 1494 arguments.positional[0].getStaticType(types));
1482 } 1495 }
1483 Class superclass = target.enclosingClass; 1496 Class superclass = target.enclosingClass;
1484 var receiverType = receiver.getStaticTypeAsInstanceOf(superclass, types); 1497 var receiverType = receiver.getStaticTypeAsInstanceOf(superclass, types);
1485 var returnType = 1498 var returnType = Substitution
1486 substituteThisType(target.function.returnType, receiverType); 1499 .fromInterfaceType(receiverType)
1487 return substitutePairwise( 1500 .substituteType(target.function.returnType);
1488 returnType, target.function.typeParameters, arguments.types); 1501 return Substitution
1502 .fromPairs(target.function.typeParameters, arguments.types)
1503 .substituteType(returnType);
1489 } 1504 }
1490 } 1505 }
1491 1506
1492 /// Expression of form `super.field`. 1507 /// Expression of form `super.field`.
1493 /// 1508 ///
1494 /// This may invoke a getter, read a field, or tear off a method. 1509 /// This may invoke a getter, read a field, or tear off a method.
1495 class SuperPropertyGet extends Expression { 1510 class SuperPropertyGet extends Expression {
1496 Name name; 1511 Name name;
1497 _MemberAccessor _interfaceTargetReference; 1512 _MemberAccessor _interfaceTargetReference;
1498 1513
1499 SuperPropertyGet(this.name, [Member interfaceTarget]) { 1514 SuperPropertyGet(this.name, [Member interfaceTarget]) {
1500 _interfaceTargetReference = interfaceTarget?._getterInterface; 1515 _interfaceTargetReference = interfaceTarget?._getterInterface;
1501 } 1516 }
1502 1517
1503 Member get interfaceTarget => _interfaceTargetReference?.target; 1518 Member get interfaceTarget => _interfaceTargetReference?.target;
1504 1519
1505 void set interfaceTarget(Member newTarget) { 1520 void set interfaceTarget(Member newTarget) {
1506 _interfaceTargetReference = newTarget?._getterInterface; 1521 _interfaceTargetReference = newTarget?._getterInterface;
1507 } 1522 }
1508 1523
1509 DartType getStaticType(TypeEnvironment types) { 1524 DartType getStaticType(TypeEnvironment types) {
1510 Class declaringClass = interfaceTarget.enclosingClass; 1525 Class declaringClass = interfaceTarget.enclosingClass;
1511 if (declaringClass.typeParameters.isEmpty) { 1526 if (declaringClass.typeParameters.isEmpty) {
1512 return interfaceTarget.getterType; 1527 return interfaceTarget.getterType;
1513 } 1528 }
1514 var receiver = 1529 var receiver =
1515 types.hierarchy.getTypeAsInstanceOf(types.thisType, declaringClass); 1530 types.hierarchy.getTypeAsInstanceOf(types.thisType, declaringClass);
1516 return substituteThisType(interfaceTarget.getterType, receiver); 1531 return Substitution
1532 .fromInterfaceType(receiver)
1533 .substituteType(interfaceTarget.getterType);
1517 } 1534 }
1518 1535
1519 accept(ExpressionVisitor v) => v.visitSuperPropertyGet(this); 1536 accept(ExpressionVisitor v) => v.visitSuperPropertyGet(this);
1520 1537
1521 visitChildren(Visitor v) { 1538 visitChildren(Visitor v) {
1522 name?.accept(v); 1539 name?.accept(v);
1523 } 1540 }
1524 1541
1525 transformChildren(Transformer v) {} 1542 transformChildren(Transformer v) {}
1526 } 1543 }
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
1692 1709
1693 DartType getStaticType(TypeEnvironment types) { 1710 DartType getStaticType(TypeEnvironment types) {
1694 if (interfaceTarget != null) { 1711 if (interfaceTarget != null) {
1695 if (types.isOverloadedArithmeticOperator(interfaceTarget)) { 1712 if (types.isOverloadedArithmeticOperator(interfaceTarget)) {
1696 return types.getTypeOfOverloadedArithmetic( 1713 return types.getTypeOfOverloadedArithmetic(
1697 receiver.getStaticType(types), 1714 receiver.getStaticType(types),
1698 arguments.positional[0].getStaticType(types)); 1715 arguments.positional[0].getStaticType(types));
1699 } 1716 }
1700 Class superclass = interfaceTarget.enclosingClass; 1717 Class superclass = interfaceTarget.enclosingClass;
1701 var receiverType = receiver.getStaticTypeAsInstanceOf(superclass, types); 1718 var receiverType = receiver.getStaticTypeAsInstanceOf(superclass, types);
1702 var returnType = 1719 var returnType = Substitution
1703 substituteThisType(interfaceTarget.function.returnType, receiverType); 1720 .fromInterfaceType(receiverType)
1704 return substitutePairwise( 1721 .substituteType(interfaceTarget.function.returnType);
1705 returnType, interfaceTarget.function.typeParameters, arguments.types); 1722 return Substitution
1723 .fromPairs(interfaceTarget.function.typeParameters, arguments.types)
1724 .substituteType(returnType);
1706 } 1725 }
1707 if (name.name == 'call') { 1726 if (name.name == 'call') {
1708 var receiverType = receiver.getStaticType(types); 1727 var receiverType = receiver.getStaticType(types);
1709 if (receiverType is FunctionType) { 1728 if (receiverType is FunctionType) {
1710 if (receiverType.typeParameters.length != arguments.types.length) { 1729 if (receiverType.typeParameters.length != arguments.types.length) {
1711 return const BottomType(); 1730 return const BottomType();
1712 } 1731 }
1713 return substitutePairwise(receiverType.returnType, 1732 return Substitution
1714 receiverType.typeParameters, arguments.types); 1733 .fromPairs(receiverType.typeParameters, arguments.types)
1734 .substituteType(receiverType.returnType);
1715 } 1735 }
1716 } 1736 }
1717 if (name.name == '==') { 1737 if (name.name == '==') {
1718 // We use this special case to simplify generation of '==' checks. 1738 // We use this special case to simplify generation of '==' checks.
1719 return types.boolType; 1739 return types.boolType;
1720 } 1740 }
1721 return const DynamicType(); 1741 return const DynamicType();
1722 } 1742 }
1723 1743
1724 accept(ExpressionVisitor v) => v.visitMethodInvocation(this); 1744 accept(ExpressionVisitor v) => v.visitMethodInvocation(this);
(...skipping 27 matching lines...) Expand all
1752 1772
1753 SuperMethodInvocation(this.name, this.arguments, this.interfaceTarget) { 1773 SuperMethodInvocation(this.name, this.arguments, this.interfaceTarget) {
1754 arguments?.parent = this; 1774 arguments?.parent = this;
1755 } 1775 }
1756 1776
1757 DartType getStaticType(TypeEnvironment types) { 1777 DartType getStaticType(TypeEnvironment types) {
1758 if (interfaceTarget == null) return const DynamicType(); 1778 if (interfaceTarget == null) return const DynamicType();
1759 Class superclass = interfaceTarget.enclosingClass; 1779 Class superclass = interfaceTarget.enclosingClass;
1760 var receiverType = 1780 var receiverType =
1761 types.hierarchy.getTypeAsInstanceOf(types.thisType, superclass); 1781 types.hierarchy.getTypeAsInstanceOf(types.thisType, superclass);
1762 var returnType = 1782 var returnType = Substitution
1763 substituteThisType(interfaceTarget.function.returnType, receiverType); 1783 .fromInterfaceType(receiverType)
1764 return substitutePairwise( 1784 .substituteType(interfaceTarget.function.returnType);
1765 returnType, interfaceTarget.function.typeParameters, arguments.types); 1785 return Substitution
1786 .fromPairs(interfaceTarget.function.typeParameters, arguments.types)
1787 .substituteType(returnType);
1766 } 1788 }
1767 1789
1768 accept(ExpressionVisitor v) => v.visitSuperMethodInvocation(this); 1790 accept(ExpressionVisitor v) => v.visitSuperMethodInvocation(this);
1769 1791
1770 visitChildren(Visitor v) { 1792 visitChildren(Visitor v) {
1771 name?.accept(v); 1793 name?.accept(v);
1772 arguments?.accept(v); 1794 arguments?.accept(v);
1773 } 1795 }
1774 1796
1775 transformChildren(Transformer v) { 1797 transformChildren(Transformer v) {
(...skipping 15 matching lines...) Expand all
1791 /// True if this is a constant call to an external constant factory. 1813 /// True if this is a constant call to an external constant factory.
1792 bool isConst; 1814 bool isConst;
1793 1815
1794 Name get name => target?.name; 1816 Name get name => target?.name;
1795 1817
1796 StaticInvocation(this.target, this.arguments, {this.isConst: false}) { 1818 StaticInvocation(this.target, this.arguments, {this.isConst: false}) {
1797 arguments?.parent = this; 1819 arguments?.parent = this;
1798 } 1820 }
1799 1821
1800 DartType getStaticType(TypeEnvironment types) { 1822 DartType getStaticType(TypeEnvironment types) {
1801 return substitutePairwise(target.function.returnType, 1823 return Substitution
1802 target.function.typeParameters, arguments.types); 1824 .fromPairs(target.function.typeParameters, arguments.types)
1825 .substituteType(target.function.returnType);
1803 } 1826 }
1804 1827
1805 accept(ExpressionVisitor v) => v.visitStaticInvocation(this); 1828 accept(ExpressionVisitor v) => v.visitStaticInvocation(this);
1806 1829
1807 visitChildren(Visitor v) { 1830 visitChildren(Visitor v) {
1808 target?.acceptReference(v); 1831 target?.acceptReference(v);
1809 arguments?.accept(v); 1832 arguments?.accept(v);
1810 } 1833 }
1811 1834
1812 transformChildren(Transformer v) { 1835 transformChildren(Transformer v) {
(...skipping 1583 matching lines...) Expand 10 before | Expand all | Expand 10 after
3396 3419
3397 transformChildren(Transformer v) { 3420 transformChildren(Transformer v) {
3398 bound = v.visitDartType(bound); 3421 bound = v.visitDartType(bound);
3399 } 3422 }
3400 3423
3401 /// Returns a possibly synthesized name for this type parameter, consistent 3424 /// Returns a possibly synthesized name for this type parameter, consistent
3402 /// with the names used across all [toString] calls. 3425 /// with the names used across all [toString] calls.
3403 String toString() => debugQualifiedTypeParameterName(this); 3426 String toString() => debugQualifiedTypeParameterName(this);
3404 } 3427 }
3405 3428
3429 class Supertype extends Node {
3430 final Class classNode;
3431 final List<DartType> typeArguments;
3432
3433 Supertype(this.classNode, this.typeArguments);
3434
3435 accept(Visitor v) => v.visitSupertype(this);
3436
3437 visitChildren(Visitor v) {
3438 classNode.acceptReference(v);
3439 visitList(typeArguments, v);
3440 }
3441
3442 InterfaceType get asInterfaceType {
3443 return new InterfaceType(classNode, typeArguments);
3444 }
3445
3446 bool operator ==(Object other) {
3447 if (identical(this, other)) return true;
3448 if (other is Supertype) {
3449 if (classNode != other.classNode) return false;
3450 if (typeArguments.length != other.typeArguments.length) return false;
3451 for (int i = 0; i < typeArguments.length; ++i) {
3452 if (typeArguments[i] != other.typeArguments[i]) return false;
3453 }
3454 return true;
3455 } else {
3456 return false;
3457 }
3458 }
3459
3460 int get hashCode {
3461 int hash = 0x3fffffff & classNode.hashCode;
3462 for (int i = 0; i < typeArguments.length; ++i) {
3463 hash = 0x3fffffff & (hash * 31 + (hash ^ typeArguments[i].hashCode));
3464 }
3465 return hash;
3466 }
3467 }
3468
3406 // ------------------------------------------------------------------------ 3469 // ------------------------------------------------------------------------
3407 // PROGRAM 3470 // PROGRAM
3408 // ------------------------------------------------------------------------ 3471 // ------------------------------------------------------------------------
3409 3472
3410 /// A way to bundle up all the libraries in a program. 3473 /// A way to bundle up all the libraries in a program.
3411 class Program extends TreeNode { 3474 class Program extends TreeNode {
3412 final List<Library> libraries; 3475 final List<Library> libraries;
3413 3476
3414 /// Map from a source file uri to a line-starts table. 3477 /// Map from a source file uri to a line-starts table.
3415 /// Given a source file uri and a offset in that file one can translate 3478 /// Given a source file uri and a offset in that file one can translate
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
3466 if (result != null) { 3529 if (result != null) {
3467 nodes[storeIndex] = result; 3530 nodes[storeIndex] = result;
3468 ++storeIndex; 3531 ++storeIndex;
3469 } 3532 }
3470 } 3533 }
3471 if (storeIndex < nodes.length) { 3534 if (storeIndex < nodes.length) {
3472 nodes.length = storeIndex; 3535 nodes.length = storeIndex;
3473 } 3536 }
3474 } 3537 }
3475 3538
3539 void transformSupertypeList(List<Supertype> nodes, Transformer visitor) {
3540 int storeIndex = 0;
3541 for (int i = 0; i < nodes.length; ++i) {
3542 var result = visitor.visitSupertype(nodes[i]);
3543 if (result != null) {
3544 nodes[storeIndex] = result;
3545 ++storeIndex;
3546 }
3547 }
3548 if (storeIndex < nodes.length) {
3549 nodes.length = storeIndex;
3550 }
3551 }
3552
3476 void transformList(List<TreeNode> nodes, Transformer visitor, TreeNode parent) { 3553 void transformList(List<TreeNode> nodes, Transformer visitor, TreeNode parent) {
3477 int storeIndex = 0; 3554 int storeIndex = 0;
3478 for (int i = 0; i < nodes.length; ++i) { 3555 for (int i = 0; i < nodes.length; ++i) {
3479 var result = nodes[i].accept(visitor); 3556 var result = nodes[i].accept(visitor);
3480 if (result != null) { 3557 if (result != null) {
3481 nodes[storeIndex] = result; 3558 nodes[storeIndex] = result;
3482 result.parent = parent; 3559 result.parent = parent;
3483 ++storeIndex; 3560 ++storeIndex;
3484 } 3561 }
3485 } 3562 }
(...skipping 17 matching lines...) Expand all
3503 3580
3504 @override 3581 @override
3505 defaultTreeNode(TreeNode node) { 3582 defaultTreeNode(TreeNode node) {
3506 if (node == child) { 3583 if (node == child) {
3507 return replacement; 3584 return replacement;
3508 } else { 3585 } else {
3509 return node; 3586 return node;
3510 } 3587 }
3511 } 3588 }
3512 } 3589 }
OLDNEW
« no previous file with comments | « lib/analyzer/loader.dart ('k') | lib/binary/ast_from_binary.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698