Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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('elements'); | 5 #library('elements'); |
| 6 | 6 |
| 7 #import('../tree/tree.dart'); | 7 #import('../tree/tree.dart'); |
| 8 #import('../scanner/scannerlib.dart'); | 8 #import('../scanner/scannerlib.dart'); |
| 9 #import('../leg.dart'); // TODO(karlklose): we only need type. | 9 #import('../leg.dart'); // TODO(karlklose): we only need type. |
| 10 #import('../util/util.dart'); | 10 #import('../util/util.dart'); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 26 | 26 |
| 27 static final int PREFIX = 8; | 27 static final int PREFIX = 8; |
| 28 | 28 |
| 29 /** Constructor or factory. */ | 29 /** Constructor or factory. */ |
| 30 static final int FACTORY = 16; | 30 static final int FACTORY = 16; |
| 31 | 31 |
| 32 static final int ALIAS = 32; | 32 static final int ALIAS = 32; |
| 33 | 33 |
| 34 static final int SUPER = 64; | 34 static final int SUPER = 64; |
| 35 | 35 |
| 36 /** Type variable */ | |
| 37 static final int TYPE_VARIABLE = 128; | |
| 38 | |
| 36 static final int IMPLIES_TYPE = CLASS | ALIAS; | 39 static final int IMPLIES_TYPE = CLASS | ALIAS; |
| 37 } | 40 } |
| 38 | 41 |
| 39 class ElementKind { | 42 class ElementKind { |
| 40 final String id; | 43 final String id; |
| 41 final int category; | 44 final int category; |
| 42 | 45 |
| 43 const ElementKind(String this.id, this.category); | 46 const ElementKind(String this.id, this.category); |
| 44 | 47 |
| 45 static final ElementKind VARIABLE = | 48 static final ElementKind VARIABLE = |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 61 static final ElementKind FIELD_LIST = | 64 static final ElementKind FIELD_LIST = |
| 62 const ElementKind('field_list', ElementCategory.NONE); | 65 const ElementKind('field_list', ElementCategory.NONE); |
| 63 static final ElementKind GENERATIVE_CONSTRUCTOR_BODY = | 66 static final ElementKind GENERATIVE_CONSTRUCTOR_BODY = |
| 64 const ElementKind('generative_constructor_body', ElementCategory.NONE); | 67 const ElementKind('generative_constructor_body', ElementCategory.NONE); |
| 65 static final ElementKind COMPILATION_UNIT = | 68 static final ElementKind COMPILATION_UNIT = |
| 66 const ElementKind('compilation_unit', ElementCategory.NONE); | 69 const ElementKind('compilation_unit', ElementCategory.NONE); |
| 67 static final ElementKind GETTER = | 70 static final ElementKind GETTER = |
| 68 const ElementKind('getter', ElementCategory.NONE); | 71 const ElementKind('getter', ElementCategory.NONE); |
| 69 static final ElementKind SETTER = | 72 static final ElementKind SETTER = |
| 70 const ElementKind('setter', ElementCategory.NONE); | 73 const ElementKind('setter', ElementCategory.NONE); |
| 74 static final ElementKind TYPE_VARIABLE = | |
| 75 const ElementKind('type_variable', ElementCategory.TYPE_VARIABLE); | |
| 71 static final ElementKind ABSTRACT_FIELD = | 76 static final ElementKind ABSTRACT_FIELD = |
| 72 const ElementKind('abstract_field', ElementCategory.VARIABLE); | 77 const ElementKind('abstract_field', ElementCategory.VARIABLE); |
| 73 static final ElementKind LIBRARY = | 78 static final ElementKind LIBRARY = |
| 74 const ElementKind('library', ElementCategory.NONE); | 79 const ElementKind('library', ElementCategory.NONE); |
| 75 static final ElementKind PREFIX = | 80 static final ElementKind PREFIX = |
| 76 const ElementKind('prefix', ElementCategory.PREFIX); | 81 const ElementKind('prefix', ElementCategory.PREFIX); |
| 77 static final ElementKind TYPEDEF = | 82 static final ElementKind TYPEDEF = |
| 78 const ElementKind('typedef', ElementCategory.ALIAS); | 83 const ElementKind('typedef', ElementCategory.ALIAS); |
| 79 | 84 |
| 80 static final ElementKind STATEMENT = | 85 static final ElementKind STATEMENT = |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 107 bool isGenerativeConstructor() => kind === ElementKind.GENERATIVE_CONSTRUCTOR; | 112 bool isGenerativeConstructor() => kind === ElementKind.GENERATIVE_CONSTRUCTOR; |
| 108 bool isCompilationUnit() { | 113 bool isCompilationUnit() { |
| 109 return kind === ElementKind.COMPILATION_UNIT || | 114 return kind === ElementKind.COMPILATION_UNIT || |
| 110 kind === ElementKind.LIBRARY; | 115 kind === ElementKind.LIBRARY; |
| 111 } | 116 } |
| 112 bool isClass() => kind === ElementKind.CLASS; | 117 bool isClass() => kind === ElementKind.CLASS; |
| 113 bool isVariable() => kind === ElementKind.VARIABLE; | 118 bool isVariable() => kind === ElementKind.VARIABLE; |
| 114 bool isParameter() => kind === ElementKind.PARAMETER; | 119 bool isParameter() => kind === ElementKind.PARAMETER; |
| 115 bool isStatement() => kind === ElementKind.STATEMENT; | 120 bool isStatement() => kind === ElementKind.STATEMENT; |
| 116 bool isTypedef() => kind === ElementKind.TYPEDEF; | 121 bool isTypedef() => kind === ElementKind.TYPEDEF; |
| 122 bool isTypeVariable() => kind === ElementKind.TYPE_VARIABLE; | |
| 117 bool isGetter() => kind === ElementKind.GETTER; | 123 bool isGetter() => kind === ElementKind.GETTER; |
| 118 bool impliesType() => (kind.category & ElementCategory.IMPLIES_TYPE) != 0; | 124 bool impliesType() => (kind.category & ElementCategory.IMPLIES_TYPE) != 0; |
| 119 | 125 |
| 120 bool isAssignable() { | 126 bool isAssignable() { |
| 121 if (modifiers != null && modifiers.isFinal()) return false; | 127 if (modifiers != null && modifiers.isFinal()) return false; |
| 122 if (isFunction() || isGenerativeConstructor()) return false; | 128 if (isFunction() || isGenerativeConstructor()) return false; |
| 123 return true; | 129 return true; |
| 124 } | 130 } |
| 125 | 131 |
| 126 Token position() => null; | 132 Token position() => null; |
| (...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 626 } | 632 } |
| 627 | 633 |
| 628 class ClassElement extends ContainerElement { | 634 class ClassElement extends ContainerElement { |
| 629 Type type; | 635 Type type; |
| 630 Type supertype; | 636 Type supertype; |
| 631 Type defaultClass; | 637 Type defaultClass; |
| 632 Link<Element> members = const EmptyLink<Element>(); | 638 Link<Element> members = const EmptyLink<Element>(); |
| 633 Map<SourceString, Element> localMembers; | 639 Map<SourceString, Element> localMembers; |
| 634 Map<SourceString, Element> constructors; | 640 Map<SourceString, Element> constructors; |
| 635 Link<Type> interfaces = const EmptyLink<Type>(); | 641 Link<Type> interfaces = const EmptyLink<Type>(); |
| 642 Map<SourceString, TypeVariableElement> typeParameters; | |
| 636 bool isResolved = false; | 643 bool isResolved = false; |
| 637 bool isBeingResolved = false; | 644 bool isBeingResolved = false; |
| 638 // backendMembers are members that have been added by the backend to simplify | 645 // backendMembers are members that have been added by the backend to simplify |
| 639 // compilation. They don't have any user-side counter-part. | 646 // compilation. They don't have any user-side counter-part. |
| 640 Link<Element> backendMembers = const EmptyLink<Element>(); | 647 Link<Element> backendMembers = const EmptyLink<Element>(); |
| 641 | 648 |
| 642 Link<Type> allSupertypes; | 649 Link<Type> allSupertypes; |
| 643 | 650 |
| 644 ClassElement(SourceString name, CompilationUnitElement enclosing) | 651 ClassElement(SourceString name, CompilationUnitElement enclosing) |
| 645 : localMembers = new Map<SourceString, Element>(), | 652 : localMembers = new Map<SourceString, Element>(), |
| 646 constructors = new Map<SourceString, Element>(), | 653 constructors = new Map<SourceString, Element>(), |
| 654 typeParameters = new Map<SourceString, TypeVariableElement>(), | |
| 647 super(name, ElementKind.CLASS, enclosing); | 655 super(name, ElementKind.CLASS, enclosing); |
| 648 | 656 |
| 649 void addMember(Element element, DiagnosticListener listener) { | 657 void addMember(Element element, DiagnosticListener listener) { |
| 650 members = members.prepend(element); | 658 members = members.prepend(element); |
| 651 if (element.kind == ElementKind.GENERATIVE_CONSTRUCTOR || | 659 if (element.kind == ElementKind.GENERATIVE_CONSTRUCTOR || |
| 652 element.modifiers.isFactory()) { | 660 element.modifiers.isFactory()) { |
| 653 constructors[element.name] = element; | 661 constructors[element.name] = element; |
| 654 } else if (element.kind == ElementKind.GETTER | 662 } else if (element.kind == ElementKind.GETTER |
| 655 || element.kind == ElementKind.SETTER) { | 663 || element.kind == ElementKind.SETTER) { |
| 656 addGetterOrSetter(element, localMembers[element.name], listener); | 664 addGetterOrSetter(element, localMembers[element.name], listener); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 669 ClassElement ensureResolved(Compiler compiler) { | 677 ClassElement ensureResolved(Compiler compiler) { |
| 670 if (!isResolved && !isBeingResolved) { | 678 if (!isResolved && !isBeingResolved) { |
| 671 isBeingResolved = true; | 679 isBeingResolved = true; |
| 672 compiler.resolveType(this); | 680 compiler.resolveType(this); |
| 673 isBeingResolved = false; | 681 isBeingResolved = false; |
| 674 isResolved = true; | 682 isResolved = true; |
| 675 } | 683 } |
| 676 return this; | 684 return this; |
| 677 } | 685 } |
| 678 | 686 |
| 687 Element lookupTypeParameter(SourceString parameterName) { | |
|
ahe
2012/03/15 11:17:33
As far as I can tell, this creates a separate scop
karlklose
2012/03/16 14:58:47
Yes, but the resolver will try to look names up us
| |
| 688 Element result = typeParameters[parameterName]; | |
| 689 return result; | |
| 690 } | |
| 691 | |
| 679 Element lookupLocalMember(SourceString memberName) { | 692 Element lookupLocalMember(SourceString memberName) { |
| 680 return localMembers[memberName]; | 693 return localMembers[memberName]; |
| 681 } | 694 } |
| 682 | 695 |
| 683 Element lookupSuperMember(SourceString memberName) { | 696 Element lookupSuperMember(SourceString memberName) { |
| 684 for (ClassElement s = superclass; s != null; s = s.superclass) { | 697 for (ClassElement s = superclass; s != null; s = s.superclass) { |
| 685 Element e = s.lookupLocalMember(memberName); | 698 Element e = s.lookupLocalMember(memberName); |
| 686 if (e !== null) return e; | 699 if (e !== null) return e; |
| 687 } | 700 } |
| 688 return null; | 701 return null; |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 874 return result; | 887 return result; |
| 875 } | 888 } |
| 876 | 889 |
| 877 Node parseNode(DiagnosticListener l) => statement; | 890 Node parseNode(DiagnosticListener l) => statement; |
| 878 | 891 |
| 879 bool get isSwitch() => statement is SwitchStatement; | 892 bool get isSwitch() => statement is SwitchStatement; |
| 880 | 893 |
| 881 Token position() => statement.getBeginToken(); | 894 Token position() => statement.getBeginToken(); |
| 882 String toString() => statement.toString(); | 895 String toString() => statement.toString(); |
| 883 } | 896 } |
| 897 | |
| 898 class TypeVariableElement extends Element { | |
|
ahe
2012/03/15 11:17:33
Please override toString to include the name of th
karlklose
2012/03/16 14:58:47
Done.
| |
| 899 final Node node; | |
| 900 Type bound; | |
| 901 Type type; | |
| 902 TypeVariableElement(name, Element enclosing, this.node, this.type, | |
|
ngeoffray
2012/03/15 11:47:40
I prefer having enclosing at the end.
| |
| 903 [this.bound]) | |
|
ngeoffray
2012/03/15 11:47:40
should that default to Object to avoid null checks
karlklose
2012/03/16 14:58:47
The bound is set when resolving the class containi
| |
| 904 : super(name, ElementKind.TYPE_VARIABLE, enclosing); | |
| 905 Type computeType(compiler) => type; | |
| 906 Node parseNode(compiler) => node; | |
| 907 } | |
| OLD | NEW |